<template>

	<view class="goods_item">

		<!-- 左侧的盒子 -->
		<view class="goods_item_left">
			<radio :checked="goods.goods_state" v-if="showRadio" color="#C00000" @click="radioClickHandler" />
			<image :src="goods.goods_small_logo || defaultPic" class="goods_pic"></image>
		</view>
		<!-- 右侧的盒子 -->
		<view class="goods_iten_right">
			<!-- 商品的名字 -->
			<view class="goods_name">
				{{goods.goods_name}}
			</view>
			<view class="goods_info_box">
				<view class="goods_price">
					¥{{goods.goods_price | toFixed }}
				</view>

				<uni-number-box v-if="showNum" :min="1" :value="goods.goods_count" @change="numberChangeHandler">
				</uni-number-box>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		name: "my-goods",
		data() {
			return {
				defaultPic: "https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png"
			};
		},
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				//是否显示左侧的 radio组件
				type: Boolean,
				default: false
			},
			showNum: {
				//是否显示商品数量改变按钮
				type: Boolean,
				default: false
			}
		},
		filters: {
			toFixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			//radio 组件的点击事件处理函数

			radioClickHandler() {
				console.log(this.goods.goods_state)
				this.$emit("radio-change", {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			//监听到 NumberBox 数量发生变化
			numberChangeHandler(val) {
				this.$emit("num-change", {
					goods_id: this.goods.goods_id,
					goods_count: +val
				})
			}

		}
	}
</script>

<style lang="scss">
	.goods_item {
		width: 750rpx;
		box-sizing: border-box;
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #F0F0F0;

		.goods_item_left {
			margin-right: 5px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.goods_pic {
				width: 100px;
				height: 100px;
			}
		}

		.goods_iten_right {

			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;

			.goods_name {
				font-size: 13px;
			}

			.goods_info_box {

				display: flex;
				justify-content: space-between;
				align-items: center;

				.goods_price {
					color: #C00000;
					font-size: 19px;
				}
			}
		}

	}
</style>
